package com.wsl.redis.domain;

import com.wsl.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 8:56 2017/12/1
 * @Modified by:
 */
@Repository
public class PersonDao {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Resource(name = "stringRedisTemplate")
    ValueOperations<String,String> valueOperationsStr;
    @Autowired
    RedisTemplate<Object,Object> redisTemplate;
    @Resource(name="redisTemplate")
    ValueOperations<Object,Object> valueOperationsObj;

    public void stringRedisTemplate(String key,String value){
        valueOperationsStr.set(key,value);
    }

    public void save(Person person){
        valueOperationsObj.set(person.getId(),person);
    }

    public String getString(String key){
        return valueOperationsStr.get(key);
    }

    public Person getPerson(String  id){
        return (Person)valueOperationsObj.get(id);
    }
}